from kiwi.core.base import Model
import numpy as np

#*****************************************************************************
# PURPOSE: 
# USAGE:   
# PASSED ARGS:  
# RETURN ARGS: 
# Error - Fail Error Message
#*****************************************************************************
class Learner( Model ):
	#*****************************************************************************
	# PURPOSE: 
	# USAGE:   
	# PASSED ARGS:  
	# RETURN ARGS: 
	# Error - Fail Error Message
	#*****************************************************************************
	def __init__( self, name = "Learner" , type = "Learner"  ):
		Model.__init__( self, name , type  )

	#*****************************************************************************
	# PURPOSE: 
	# USAGE:   
	# PASSED ARGS:  
	# RETURN ARGS: 
	# Error - Fail Error Message
	#*****************************************************************************	
	def __del__( self ):
		Model.__del__( self )
		if self.trainset is not None: del self.trainset
		if self.testset  is not None: del self.testset
	
	#*****************************************************************************
	# PURPOSE: 
	# USAGE:   
	# PASSED ARGS:  
	# RETURN ARGS: 
	# Error - Fail Error Message
	#*****************************************************************************	
	def setTrainSet( self,  instances ):
		self.trainset = instances
	
	#*****************************************************************************
	# PURPOSE: 
	# USAGE:   
	# PASSED ARGS:  
	# RETURN ARGS: 
	# Error - Fail Error Message
	#*****************************************************************************	
	def getTrainSet( self ):
		return self.trainset

	#*****************************************************************************
	# PURPOSE: 
	# USAGE:   
	# PASSED ARGS:  
	# RETURN ARGS: 
	# Error - Fail Error Message
	#*****************************************************************************	
	def setTestSet( self, instances ):
		self.testset = instances

	#*****************************************************************************
	# PURPOSE: 
	# USAGE:   
	# PASSED ARGS:  
	# RETURN ARGS: 
	# Error - Fail Error Message
	#*****************************************************************************		
	def getTestSet( self, instances ):
		return self.testset

	#*****************************************************************************
	# PURPOSE: 
	# USAGE:   
	# PASSED ARGS:  
	# RETURN ARGS: 
	# Error - Fail Error Message
	#*****************************************************************************
	def build( self,  instances = None ):
		pass
	
	#*****************************************************************************
	# PURPOSE: 
	# USAGE:   
	# PASSED ARGS:  
	# RETURN ARGS: 
	# Error - Fail Error Message
	#*****************************************************************************
	def predictInstance( self, instance ):
		pass

	#*****************************************************************************
	# PURPOSE: 
	# USAGE:   
	# PASSED ARGS:  
	# RETURN ARGS: 
	# Error - Fail Error Message
	#*****************************************************************************
	def predict( self, instances ):
		return [ self.predictInstance( instance ) \
					             for instance in instances ] 

		
#*****************************************************************************
# PURPOSE: 
# USAGE:   
# PASSED ARGS:  
# RETURN ARGS: 
# Error - Fail Error Message
#*****************************************************************************
class Classifier( Learner ):
	#*****************************************************************************
	# PURPOSE: 
	# USAGE:   
	# PASSED ARGS:  
	# RETURN ARGS: 
	# Error - Fail Error Message
	#*****************************************************************************	
	def __init__( self, name = "Classifier" , type = "Classifier" ):
		Learner.__init__(self, name, type  )

	#*****************************************************************************
	# PURPOSE: 
	# USAGE:   
	# PASSED ARGS:  
	# RETURN ARGS: 
	# Error - Fail Error Message
	#*****************************************************************************		
	def	__del__( self ):
		Learner.__del__( self )
	
	#*****************************************************************************
	# PURPOSE: 
	# USAGE:   
	# PASSED ARGS:  
	# RETURN ARGS: 
	# Error - Fail Error Message
	#*****************************************************************************	
	def buildClassifier( self,  instances ):
		pass

	#*****************************************************************************
	# PURPOSE: 
	# USAGE:   
	# PASSED ARGS:  
	# RETURN ARGS: 
	# Error - Fail Error Message
	#*****************************************************************************
	def build( self, instances = None ):
		if instances is not None:
			self.trainset = instances
		if self.trainset is not None:
			self.buildClassifier( self.trainset )

	#*****************************************************************************
	# PURPOSE: 
	# USAGE:   
	# PASSED ARGS:  
	# RETURN ARGS: 
	# Error - Fail Error Message
	#*****************************************************************************
	def classifyInstance( self, instance ):
		pass

	#*****************************************************************************
	# PURPOSE: 
	# USAGE:   
	# PASSED ARGS:  
	# RETURN ARGS: 
	# Error - Fail Error Message
	#*****************************************************************************
	def predictInstance( self, instance ):
		return self.classifyInstance( instance )

#*****************************************************************************
# PURPOSE: 
# USAGE:   
# PASSED ARGS:  
# RETURN ARGS: 
# Error - Fail Error Message
#*****************************************************************************
class Cluster( Learner ):
	#*****************************************************************************
	# PURPOSE: 
	# USAGE:   
	# PASSED ARGS:  
	# RETURN ARGS: 
	# Error - Fail Error Message
	#*****************************************************************************	
	def __init__( self, name = "Cluster" , type = "Cluster" ):
		Learner.__init__(self, name, type  )

	#*****************************************************************************
	# PURPOSE: 
	# USAGE:   
	# PASSED ARGS:  
	# RETURN ARGS: 
	# Error - Fail Error Message
	#*****************************************************************************		
	def	__del__( self ):
		Learner.__del__( self )

	#*****************************************************************************
	# PURPOSE: 
	# USAGE:   
	# PASSED ARGS:  
	# RETURN ARGS: 
	# Error - Fail Error Message
	#*****************************************************************************	
	def buildCluster( self,  instances ):
		pass

	#*****************************************************************************
	# PURPOSE: 
	# USAGE:   
	# PASSED ARGS:  
	# RETURN ARGS: 
	# Error - Fail Error Message
	#*****************************************************************************
	def build( self, instances = None ):
		if instances is not None:
			self.instances = instances
		if self.instances is not None:
			self.buildCluster( self.instances )

	#*****************************************************************************
	# PURPOSE: 
	# USAGE:   
	# PASSED ARGS:  
	# RETURN ARGS: 
	# Error - Fail Error Message
	#*****************************************************************************
	def clusterInstance( self,  instance ):
		pass

	#*****************************************************************************
	# PURPOSE: 
	# USAGE:   
	# PASSED ARGS:  
	# RETURN ARGS: 
	# Error - Fail Error Message
	#*****************************************************************************
	def predictInstance( self, instance ):
		return self.clusterInstance( instance )

#*****************************************************************************
# PURPOSE: 
# USAGE:   
# PASSED ARGS:  
# RETURN ARGS: 
# Error - Fail Error Message
#*****************************************************************************
class Regressor( Learner ):
	#*****************************************************************************
	# PURPOSE: 
	# USAGE:   
	# PASSED ARGS:  
	# RETURN ARGS: 
	# Error - Fail Error Message
	#*****************************************************************************	
	def __init__( self, name = "Regressor" , type = "Regressor" ):
		Learner.__init__(self, name, type  )


	#*****************************************************************************
	# PURPOSE: 
	# USAGE:   
	# PASSED ARGS:  
	# RETURN ARGS: 
	# Error - Fail Error Message
	#*****************************************************************************	
	def buildRegressor(self,  instances ):
		pass

	#*****************************************************************************
	# PURPOSE: 
	# USAGE:   
	# PASSED ARGS:  
	# RETURN ARGS: 
	# Error - Fail Error Message
	#*****************************************************************************
	def build( self, instances = None ):
		if instances is not None:
			self.instances = instances
		if self.instances is not None:
			self.buildRegressor( self.instances )

	#*****************************************************************************
	# PURPOSE: 
	# USAGE:   
	# PASSED ARGS:  
	# RETURN ARGS: 
	# Error - Fail Error Message
	#*****************************************************************************
	def regressInstance( self,  instance ):
		pass

	#*****************************************************************************
	# PURPOSE: 
	# USAGE:   
	# PASSED ARGS:  
	# RETURN ARGS: 
	# Error - Fail Error Message
	#*****************************************************************************
	def predictInstance( self, instance ):
		return self.regressInstance( instance )	

#*****************************************************************************
# PURPOSE: 
# USAGE:   
# PASSED ARGS:  
# RETURN ARGS: 
# Error - Fail Error Message
#*****************************************************************************
class Associator( Learner ):
	#*****************************************************************************
	# PURPOSE: 
	# USAGE:   
	# PASSED ARGS:  
	# RETURN ARGS: 
	# Error - Fail Error Message
	#*****************************************************************************	
	def __init__( self, name = "Associator" , type = "Associator" ):
		Learner.__init__( self, name, type  )

	#*****************************************************************************
	# PURPOSE: 
	# USAGE:   
	# PASSED ARGS:  
	# RETURN ARGS: 
	# Error - Fail Error Message
	#*****************************************************************************	
	def buildAssociater( self,  instances ):
		pass

	#*****************************************************************************
	# PURPOSE: 
	# USAGE:   
	# PASSED ARGS:  
	# RETURN ARGS: 
	# Error - Fail Error Message
	#*****************************************************************************
	def build( self, instances = None ):
		if instances is not None:
			self.instances = instances
		if self.instances is not None:
			self.buildAssociater( self.instances )

	#*****************************************************************************
	# PURPOSE: 
	# USAGE:   
	# PASSED ARGS:  
	# RETURN ARGS: 
	# Error - Fail Error Message
	#*****************************************************************************
	def associateInstance( self, instance ):
		pass

	#*****************************************************************************
	# PURPOSE: 
	# USAGE:   
	# PASSED ARGS:  
	# RETURN ARGS: 
	# Error - Fail Error Message
	#*****************************************************************************
	def predictInstance( self, instance ):
		return self.associateInstance( instance )	
